<template>
  <div>
    <div class="title">
      <el-row>
        <el-col :span="1" style="width: 50px;">
          <span style="color:#757575;">位置 : </span>
        </el-col>
        <el-col :span="20">
          <span class="hand">任务设置</span>
        </el-col>
      </el-row>
    </div>
    <div class="main">
      <div class="district tasksetting">
        <el-row type="flex" justify="space-between">
          <el-col :span="4" class="tabletitle">
            <h4>任务数量</h4>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="23">
            <el-row style="margin-bottom: 10px;" :gutter="50">
              <el-col :lg="6" :xl="4" v-for="(item,index) in task.partList" :key="index">
                <div class="box">
                  <el-row class="roletitle">
                    <el-col :span="11" :offset="1">
                      <p>
                        {{item.partName}}
                      </p>
                    </el-col>
                    <el-col :span="4" :offset="8">
                      <div class="operation">
                        <i class="iconfont icon-xiugai" @click="leader(item.partId,item.partName)"></i>
                      </div>
                    </el-col>
                  </el-row>
                  <el-row class="districtel">
                    <el-col class="bottom" v-for="(item1,index1) in item.list" :key="index1">
                      <el-col :span="10" :offset="2">
                        <div v-if="index1 == 0" class="pic" style="background-color: #1198fc;">
                          <img src='../../../static/image/leader.png'>
                        </div>
                        <div v-if="index1 == 1" class="pic" style="background-color: #52be85;">
                          <img src='../../../static/image/leader.png'>
                        </div>
                        {{item1.detailType}}
                      </el-col>
                      <el-col :span="4" :offset="8">
                        <p>{{item1.numLimit}}</p>
                      </el-col>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </div>
      <div class="district tasksetting">
        <el-row type="flex" justify="space-between">
          <el-col :span="4" class="tabletitle">
            <h4>{{resume.mainName}}</h4>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="23">
            <el-col :span="18" style="margin-bottom: 10px;">
              <el-col :span="8" v-for="(item,index) in resume.partList" :key="index">
                <div class="box">
                  <el-row class="roletitle">
                    <el-col :span="10" :offset="1">
                      <p>
                        {{item.partName}}
                      </p>
                    </el-col>
                    <el-col :span="4" :offset="8">
                      <div class="operation">
                        <i class="iconfont icon-xiugai" @click='resumeedit(item.partId)'></i>
                      </div>
                    </el-col>
                  </el-row>
                  <el-row class="districtel">
                    <el-col class="bottom" v-for="(item1,index1) in item.list" :key="index1">
                      <el-col :span="10" :offset="2">
                        <div v-if="index1 == 0" class="pic" style="background-color: #1198fc;">
                          <img src='../../../static/image/leader.png'>
                        </div>
                        <div v-if="index1 == 1" class="pic" style="background-color: #52be85;">
                          <img src='../../../static/image/leader.png'>
                        </div>
                        {{item1.detailType}}
                      </el-col>
                      <el-col :span="4" :offset="8">
                        <p>{{item1.numLimit}}</p>
                      </el-col>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
            </el-col>

          </el-col>
        </el-row>
      </div>
      <div class="district tasksetting">
        <el-row type="flex" justify="space-between">
          <el-col :span="4" class="tabletitle">
            <h4>岗位人员数量</h4>
          </el-col>
        </el-row>
        <el-row type="flex" justify="space-around">
          <el-col :span="23">
            <el-row style="margin-bottom: 10px;" :gutter="50">

              <!--work-->
              <el-col :lg="6" :xl="4" v-for="(item,index) in work.partList" :key="index">
                <div class="box">
                  <el-row class="roletitle">
                    <el-col :span="10" v-if="index == 4" :offset="1">
                      <i class="el-icon-star-off"></i>
                    </el-col>
                    <el-col :span="10" v-if="index == 3" :offset="1" style="color:#ffbe29;">
                      <i class="el-icon-star-on"></i>
                    </el-col>
                    <el-col :span="10" v-if="index == 2" :offset="1" style="color:#f72afe;">
                      <i class="el-icon-star-on"></i>
                      <i class="el-icon-star-on"></i>
                    </el-col>
                    <el-col v-if="index == 1" :span="10" :offset="1" style="color:#2631ff;">
                      <i class="el-icon-star-on"></i>
                      <i class="el-icon-star-on"></i>
                      <i class="el-icon-star-on"></i>
                    </el-col>
                    <el-col :span="10" :offset="1" v-if="index == 0" style="color: #fe5352;">
                      <i class="el-icon-star-on"></i>
                      <i class="el-icon-star-on"></i>
                      <i class="el-icon-star-on"></i>
                      <i class="el-icon-star-on"></i>
                    </el-col>
                    <el-col :span="4" :offset="8">
                      <div class="operation">
                        <i class="iconfont icon-xiugai" @click="numedit(item.partId)"></i>
                      </div>
                    </el-col>
                  </el-row>
                  <el-row class="districtel">
                    <el-col class="bottom" v-for="(item1,index1) in item.list" :key="index1">
                      <el-col :span="10" :offset="2">
                        <div v-if="index1 == 0" class="pic" style="background-color: #1198fc;">
                          <img src='../../../static/image/leader.png'>
                        </div>
                        <div v-if="index1 == 1" class="pic" style="background-color: #52be85;">
                          <img src='../../../static/image/leader.png'>
                        </div>
                        {{item1.detailType}}
                      </el-col>
                      <el-col :span="4" :offset="8">
                        <p>{{item1.numLimit}}</p>
                      </el-col>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
            </el-row>

          </el-col>
        </el-row>
      </div>
    </div>

    <!--招聘任务修改弹出框-->
    <el-dialog
      :title="title"
      :visible.sync="edittaskdialogVisible"
      width="415px"
      :before-close="edittaskClose"
      class="addroledialog"
    >
      <div style="text-align: left">
        <el-form label-position="top" ref="taskform" :model="taskform" style="padding:0px 50px;">
          <el-form-item v-for="(item,index) in taskform.data" :key="index"
                        :prop="'data.' + index + '.numLimit'"
                        :rules="[{ required: true, message: '岗位任务数量不能为空',trigger: 'blur'},
                                  { type: 'number', message: '岗位任务数量必须为数字',trigger: 'blur'}]"
          >
            <!--:rules="Checknum"-->
            <el-col>
              <span style="color:#333;" v-if="index == 0"><span style='color:#F56C6C;'>*</span> 主岗位</span>
              <span style="color:#333;" v-if="index == 1"><span style='color:#F56C6C;'>*</span> 副岗位</span>
            </el-col>
            <el-input v-if="index == 0" placeholder="请输入主岗位任务数量"
                      style="width: 274px" v-model.number.trim="item.numLimit" @blur="judge(item.detailId,item.numLimit)"></el-input>
            <div class="el-form-item__error" v-if="index == 0">{{mainerror}}</div>
            <el-input v-if="index == 1" placeholder="请输入副岗位任务数量"
                      style="width: 274px" v-model.number.trim="item.numLimit"  @blur="judge1(item.detailId,item.numLimit)"></el-input>
            <div class="el-form-item__error" v-if="index == 1">{{viceerror}}</div>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
           <el-button class="sure" :disabled="editdis" round @click="editsend('taskform')">确 定</el-button>
    <el-button round @click="edittaskClose" class="cancel">取 消</el-button>
  </span>
    </el-dialog>
    <!--简历修改弹出框-->
    <el-dialog
      title="修改简历数量"
      :visible.sync="editresumedialogVisible"
      width="415px"
      :before-close="editresumeClose"
      class="addroledialog"
    >
      <div style="text-align: left">
        <el-form label-position="top" ref="resumeform" style="padding:0px 50px;" :model="resumeform">
          <el-form-item v-for="(item,index) in resumeform.data" :key="index"
                        :prop="'data.' + index + '.numLimit'"

                        :rules="[{ required: true, message: '简历数量不能为空',trigger: 'blur'},
                                  { type: 'number', message: '简历数量必须为数字',trigger: 'blur'}]"
          >
            <!--:rules="Checknum"-->
            <el-col>
              <span style="color:#333;" v-if="index == 0"><span style='color:#F56C6C;'>*</span> 主岗位</span>
              <span style="color:#333;" v-if="index == 1"><span style='color:#F56C6C;'>*</span> 副岗位</span>
            </el-col>
            <el-input v-if="index == 0" placeholder="请输入主岗位简历数量"
                      style="width: 274px" v-model.number.trim="item.numLimit" @blur="judge(item.detailId,item.numLimit)"></el-input>
            <div class="el-form-item__error" v-if="index == 0">{{mainerror}}</div>
            <el-input v-if="index == 1" placeholder="请输入副岗位简历数量"
                      style="width: 274px" v-model.number.trim="item.numLimit" @blur="judge1(item.detailId,item.numLimit)"></el-input>
            <div class="el-form-item__error" v-if="index == 1">{{viceerror}}</div>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
           <el-button class="sure" :disabled="resumedis" round @click="resumesend('resumeform')">确 定</el-button>
    <el-button round @click="editresumeClose" class="cancel">取 消</el-button>
  </span>
    </el-dialog>
    <!--岗位人员数量弹出框-->
    <el-dialog
      title="修改岗位人员数量"
      :visible.sync="editnumdialogVisible"
      width="415px"
      :before-close="editnumClose"
      class="addroledialog"
    >
      <div style="text-align: left">

        <el-form label-position="top" ref="numform" :model="numform" style="padding:0px 50px;">
          <el-form-item v-for="(item,index) in numform.data" :key="index"
                        :prop="'data.' + index + '.numLimit'"
                        :rules="[{ required: true, message: '岗位人员不能为空',trigger: 'blur'},
                                  { type: 'number', message: '岗位人员必须为数字',trigger: 'blur'}]"
          >
            <!--:rules="Checknum"-->
            <el-col>
              <span style="color:#333;" v-if="index == 0"><span style='color:#F56C6C;'>*</span> 主岗位</span>
              <span style="color:#333;" v-if="index == 1"><span style='color:#F56C6C;'>*</span> 副岗位</span>
            </el-col>
            <el-input v-if="index == 0" placeholder="请输入主岗位人员数量"
                      style="width: 274px" v-model.number.trim="item.numLimit" @blur="judge(item.detailId,item.numLimit)"></el-input>
            <div class="el-form-item__error" v-if="index == 0">{{mainerror}}</div>
            <el-input v-if="index == 1" placeholder="请输入副岗位人员数量"
                      style="width: 274px" v-model.number.trim="item.numLimit" @blur="judge1(item.detailId,item.numLimit)"></el-input>
            <div class="el-form-item__error" v-if="index == 1">{{viceerror}}</div>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
           <el-button class="sure" :disabled="numdis" round @click="numsend('numform')">确 定</el-button>
    <el-button round @click="editnumClose" class="cancel">取 消</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>

  import axios from 'axios'
  import qs from 'qs'

  export default {
    name: 'tasksetting',
    data() {
      return {
        edittaskdialogVisible: false,
        edittask1dialogVisible: false,
        editresumedialogVisible: false,
        editnumdialogVisible: false,
        title: '',
        task: [],
        resume: [],
        work: [],
        taskform: {
          data: []
        },
        resumeform: {
          data: []
        },
        numform: {
          data: []
        },
        mainerror: '',
        viceerror: '',
        numdis : false,
        resumedis : false,
        editdis : false
      }
    },
    created() {
      //获取数据
      axios.post(this.url + '/task/findAll').then(res => {
        this.unlogin(res.data.code);
        if (res.data.code == 200) {
          //任务
          this.task = res.data.data[0];
          //简历
          this.resume = res.data.data[1];
          //岗位
          this.work = res.data.data[2];
          this.work.partList.reverse();
        }
      })
    },
    methods: {
      //判断填写的主岗位数据是否正确
      judge(id,val){
        var form = {
          detailId: id,
          numLimit: String(val)
        };
        axios.post(this.url + '/task/judge',form).then(res => {
          this.unlogin(res.data.code);
          if(res.data.code == 200){
            if(res.data.data !== 'success'){
              this.mainerror = res.data.data;
            }else if(res.data.data == 'success'){
              this.mainerror =  '';
            }
          }
        })
      },
      //判断填写的辅岗位数据是否正确
      judge1(id,val){
        var form = {
          detailId: id,
          numLimit: String(val)
        };
        axios.post(this.url + '/task/judge',form).then(res => {
          this.unlogin(res.data.code);
          if(res.data.code == 200){
            if(res.data.data !== 'success'){
              this.viceerror = res.data.data;
            }else if(res.data.data == 'success'){
              this.viceerror = '';
            }
          }
        })
      },
      getData() {
        axios.post(this.url + '/task/findAll').then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.task = res.data.data[0];
            this.resume = res.data.data[1];
            this.work = res.data.data[2];
            this.work.partList.reverse();
          }
        })
      },
      //关闭任务管理弹出框
      edittaskClose() {
        this.editdis = false;
        this.edittaskdialogVisible = false;
        document.documentElement.style.overflow = 'auto';
        this.viceerror = '';
        this.mainerror = '';
      },
      //任务数量修改后发送数据
      editsend(formName) {
        this.$refs[formName].validate((valid) => {
          if(this.mainerror == '' && this.viceerror == '') {
              if (valid) {
                this.editdis = true;
                axios.post(this.url + '/task/update', ({data: this.taskform.data})
                ).then(res => {
                  this.unlogin(res.data.code)
                  if (res.data.code == 200) {
                    this.editdis = false;
                    this.viceerror = '';
                    this.mainerror = '';
                    this.edittaskdialogVisible = false;
                    document.documentElement.style.overflow = 'auto';
                    this.taskform.data = [];
                    this.getData();
                  }
                })
              }
            }
        })
      },
      //点击跳出任务弹出框
      leader(id, partName) {
        this.taskform.data = [];
        this.viceerror = '';
        this.mainerror = '';
        this.editdis = false;
        axios.post(this.url + '/task/getDetail', qs.stringify({
          partId: id
        })).then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.taskform.data = res.data.data;
            this.edittaskdialogVisible = true;
            document.documentElement.style.overflow = 'hidden';
            this.$nextTick(() => {
              this.$refs["taskform"].resetFields();
            });
          }
        })
        if (partName == '招聘专员组长') {
          this.title = '修改组长任务数量';
        } else if (partName == '招聘专员组员') {
          this.title = '修改专员任务数量';
        } else if (partName == '实习招聘专员组员') {
          this.title = '修改实习专员任务数量';
        }
      },
      //简历弹出框关闭
      editresumeClose() {
        this.resumedis = false;
        this.resumeform.data = [];
        this.viceerror = '';
        this.mainerror = '';
        this.editresumedialogVisible = false;
        document.documentElement.style.overflow = 'auto';
      },
      //简历修改后发送数据
      resumesend(formName) {
        this.$refs[formName].validate((valid) => {
          if(this.mainerror == '' && this.viceerror == '') {
          if (valid) {
            this.resumedis = true;
            axios.post(this.url + '/task/update', ({data: this.resumeform.data})
            ).then(res => {
              this.unlogin(res.data.code);
              if (res.data.code == 200) {
                this.resumedis = false;
                this.mainerror = '';
                this.viceerror = '';
                this.editresumedialogVisible = false;
                document.documentElement.style.overflow = 'auto';
                this.resumeform.data = [];
                this.getData();
              };
            })
          }
        }
        })
      },
      //点击弹出简历修改弹出框
      resumeedit(id) {
        this.resumeform.data = [];
        this.viceerror = '';
        this.mainerror = '';
        this.resumedis = false;
        axios.post(this.url + '/task/getDetail', qs.stringify({
          partId: id
        })).then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.resumeform.data = res.data.data;
            this.editresumedialogVisible = true;
            document.documentElement.style.overflow = 'hidden';
            this.$nextTick(() => {
              this.$refs["resumeform"].resetFields();
            });
          }
        })
      },
      //关闭岗位人员弹出框
      editnumClose() {
        this.numdis = false;
        this.numform.data = [];
        this.viceerror = '';
        this.mainerror = '';
        this.editnumdialogVisible = false;
        document.documentElement.style.overflow = 'auto';
      },
      //发送岗位人员修改后的数据
      numsend(formName) {
        this.$refs[formName].validate((valid) => {
          if(this.mainerror == '' && this.viceerror == ''){
            if (valid) {
              this.numdis = true;
              axios.post(this.url + '/task/update', ({data: this.numform.data})
              ).then(res => {
                this.unlogin(res.data.code);
                if (res.data.code == 200) {
                  this.numdis = false;
                  this.viceerror = '';
                  this.mainerror = '';
                  this.editnumdialogVisible = false;
                  document.documentElement.style.overflow = 'auto';
                  this.numform.data = [];
                  this.getData();
                }
              })
            }
          }
        })

      },
      //点击弹出岗位人数弹出框
      numedit(id) {
        this.viceerror = '';
        this.mainerror = '';
        this.numform.data = [];
        axios.post(this.url + '/task/getDetail', qs.stringify({
          partId: id
        })).then(res => {
          this.unlogin(res.data.code);
          this.numdis = false;
          if (res.data.code == 200) {
            this.numform.data = res.data.data;
            this.editnumdialogVisible = true;
            document.documentElement.style.overflow = 'hidden';
            this.$nextTick(() => {
              this.$refs["numform"].resetFields();
            });
          }
        })

      }
    },
    watch: {},
  }
</script>
<style scoped>
  .title {
    background-color: #fff;
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    padding-left: 20px;
    margin-top: 6px;
    margin-bottom: 6px;
  }

  .district {
    min-height: 236px;
    background-color: #fff;
    margin-bottom: 10px;
  }

  .tabletitle {
    margin-left: 20px;
    height: 50px;
    line-height: 50px;
  }
  .box {
    width: 285px;
    height: 164px;
    border: 1px solid #ececec;
    margin-bottom: 30px;
    border-radius: 10px;
  }

  .roletitle {
    padding-top: 20px;
  }

  .roletitle p {
    color: #333;
    font-weight: 700;
  }

  .operation {
    width: 40px;
    height: 24px;
    background-color: #e4edfb;
    text-align: center;
  }

  .operation i {
    font-size: 14px;
    cursor: pointer;
    color: #757575;;
  }

  .operation i:hover {
    color: #119aff;
  }

  .districtel {
    margin-top: 20px;
    vertical-align: middle;
    color: #757575;
  }

  .districtel i {
    font-size: 26px;
  }

  .districtel span {
    font-size: 16px;
    position: relative;
    top: -4px;
  }

  .box:hover {
    border-color: transparent;
    box-shadow: 0px 0px 10px #ccc;
  }

  .pic {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    text-align: center;
    display: inline-block;
    vertical-align: middle;
  }

  .pic img {
    margin-top: 4px;
  }

  .bottom {
    margin-bottom: 10px;
  }


  .hand {
    color: #757575;
  }
</style>
